#!/bin/bash

nblang() {
    jq '.metadata.kernelspec.language = "python"' $1 > temp.ipynb && mv temp.ipynb $1
}

nbprocess() {
    echo "nbprocess $*"
    nb="$1"
    shift
    if [ ! -f "out/$nb" ] || [ "$nb" -nt "out/$nb" ]; then
        papermill -l python "$@" "$nb" "out/_$nb"  && mv "out/_$nb" "out/$nb"
    fi
}

source ../venv/bin/activate

rm -f *.log *.out.ipynb *.stripped.ipynb _temp.ipynb

mkdir -p out

set -e

nbprocess generate-text-dataset.ipynb
nbprocess train-ocr-errors-hf.ipynb -p max_steps 100
nbprocess train-resnet50-wds.ipynb -p max_steps 10000
nbprocess train-resnet50-wids.ipynb -p max_steps 10000
nbprocess train-resnet50-multiray-wds.ipynb -p max_steps 1000
nbprocess train-resnet50-multiray-wids.ipynb -p max_steps 1000
nbprocess tesseract-wds.ipynb
